



global _main

section .data

LC0:
	db "a.dll",0
	
LC1:
	db "LoadLibrary Error[%d]",0ah,0
	
LC2:
	db "SetGlobalHook",0
	
LC3:
	db "GetProcAddress Error[%d]",0ah,0
	
LC4:
	db "SetGlobalHook OK.",0ah,0
	
LC5:
	db "SetGlobalHook ERROR.",0ah,0
	
LC6:
	db "UnsetGlobalHook",0
	
LC7:
	db "UnsetGlobalHook OK.",0ah,0
	
LC8:
	db "check stack fail!",0ah,0

extern _LoadLibraryA,_GetLastError,_printf,_GetProcAddress@8,\
_printf,_exit
section .text 
_main:
	push ebp
	mov ebp,esp 
	sub esp,0x1000
	
	mov dword [ebp-4], 0 ; hDll
	mov dword [ebp-8], 0 ; SetGlobalHook
	mov dword [ebp-12], 0 ; UnsetGlobalHook
	mov dword [ebp-16], 0 ; bRet 
	
	mov esi,esp 
	push LC0 
	call _LoadLibraryA 
	cmp esi,esp 
	call _cs 
	mov [ebp-4], eax ; hDll
	
	cmp dword [ebp-4], 0 ; hDll
	jne .Lmain_400
	
	call _GetLastError 
	mov esi,esp 
	push eax 
	push LC1 
	mov eax,0
	call _printf
	add esp,8
	cmp esi,esp
	call _cs 
	
	jmp .Lmain_20
	
.Lmain_400:
	mov esi,esp 
	push LC2
	mov eax,[ebp-4] ; hDll
	push eax
	call _GetProcAddress@8
	cmp esi,esp
	call _cs 
	mov [ebp-8], eax ; SetGlobalHook
	
	cmp dword [ebp-8], 0  ;SetGlobalHook
	jne .Lmain_390
	
	call _GetLastError
	mov esi,esp 
	push eax
	push LC3
	mov eax,0
	call _printf
	add esp,8
	cmp esi,esp
	call _cs
	
	jmp .Lmain_20
	
.Lmain_390:
	mov eax,[ebp-8] ; _SetGlobalHook
	call eax 
	mov [ebp-16], eax ; bRet
	
	mov eax,[ebp-16] ; bRet
	test eax,eax
	je .Lmain_380
	
	mov esi,esp 
	push LC4
	mov eax,0
	call _printf
	add esp,4
	cmp esi,esp 
	call _cs 
	
	jmp .Lmain_370
	
.Lmain_380:
	mov esi,esp 
	push LC5 
	call _printf
	add esp,4
	cmp esi,esp 
	call _cs 
	
.Lmain_370:
	mov esi,esp 
	push LC6 
	mov eax,[ebp-4] ; hDll
	push eax
	call _GetProcAddress@8
	cmp esi,esp 
	call _cs 
	mov [ebp-12],eax ; UnsetGlobalHook
	
	cmp dword [ebp-12], 0 ; UnsetGlobalHook
	jne .Lmain_360
	
	call _GetLastError
	mov esi,esp 
	push eax
	push LC3 
	mov eax,0
	call _printf
	add esp,8
	cmp esi,esp
	call _cs 
	
	jmp .Lmain_20
	
.Lmain_360:
	mov eax,[ebp-12] ; _UnsetGlobalHook 
	call eax 
	
	mov esi,esp 
	push LC7
	mov eax,0
	call _printf
	add esp,4
	cmp esi,esp 
	call _cs 

.Lmain_20:
	
	mov eax,0
	leave
	ret 
	
_cs:
	je .Lcs_0
	
	push LC8 
	mov eax,0
	call _printf 
	
	push 0
	call _exit 
	
.Lcs_0:
	ret 